package com.liangtian.mdm.dm.checkRule.service.impl;

import com.liangtian.mdm.dm.checkRule.dao.CheckRuleDao;
import com.liangtian.mdm.dm.checkRule.model.CheckRule;
import com.liangtian.mdm.dm.checkRule.service.CheckRuleService;
import com.liangtian.mdm.dm.model.model.Model;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CheckRuleServiceImpl implements CheckRuleService {

    @Autowired
    CheckRuleDao checkRuleDao;

    @Override
    public PageInfo queryAllCheckByCondition(Map<String, Object> map) {

        PageInfo<List<Model>> pageInfo = null;
        try {
            Object pNo = map.get("pageNum");
            int pageNum, pageSize;
            // export
            if (pNo != null && !"NaN".equals(pNo)) {
                pageNum = Integer.parseInt(pNo.toString());// 页码
            } else {
                pageNum = 1;
            }
            // pageSize=0时不分页
            pageSize = Integer.parseInt(map.get("limit").toString());// 模型定义页面要显示数据条数
            PageHelper.startPage(pageNum, pageSize);// 开始分页标志（当前页，显示条数）

            List<CheckRule> checkRuleMapList = checkRuleDao.queryAllCheckByCondition(map);
            pageInfo = new PageInfo(checkRuleMapList);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return pageInfo;

    }

    @Override
    public void updateRule(CheckRule checkRule) {
        checkRuleDao.updateRule(checkRule);

    }

    @Override
    public int checkRuleEdit(Map<String, String> map) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public int insertRule(CheckRule checkRule) {
        int count = checkRuleDao.insertRule(checkRule);
        return count;
    }

    @Override
    public int checkRuleName(CheckRule checkRule) {
        int count = checkRuleDao.checkRuleEdit(checkRule);
        return count;
    }

    @Override
    public CheckRule getById(String id) {
        return checkRuleDao.getById(id);
    }

    /**
     * <p>TODO</p>
     *
     * @param : @param map
     * @param : @return
     * @author : xiaoliu
     * @date :2017年3月27日上午11:19:48
     */

    @Override
    public List<CheckRule> queryAllRulesByType(Map<String, Object> map) {
        List<CheckRule> checkRuleMapList = checkRuleDao.queryAllCheckByCondition(map);
        return checkRuleMapList;

    }
}
